<script language="javascript">
function getObjChange(index,obj,listStr,listId)
{
	//var myFrm = document.frmList;
	var listStr = eval('document.frmList.'+listStr);
	var listId = eval('document.frmList.'+listId);
	var lid = listId.value;
	var lst = listStr.value;
	var arrid = lid.split(",");
	var arrst = lst.split(",");
	var count = 0, i = 0;
	var mark;
	while(i<arrid.length && count==0)
	{
		if(index==arrid[i])
		{
			count++;
			mark = i;
		}
		i++;
	}
	if(count>0)
	{
		var strSt = "";
		if(obj.type=='checkbox')
		{
			if(obj.checked) arrst[mark] = '1';
			else arrst[mark] = '0';
			for(i=0;i<arrst.length-1;i++) strSt += arrst[i]+',';
			listStr.value = strSt;
		}
		else if(arrst[mark]!=obj.value)
		{
			arrst[mark] = obj.value;
			for(i=0;i<arrst.length-1;i++) strSt += arrst[i]+',';
			listStr.value = strSt;
		}
	}
	else
	{
		listId.value += index+',';
		if(obj.type=='checkbox')
		{
			if(obj.checked) listStr.value += '1,';
			else listStr.value += '0,';
		}
		else listStr.value += obj.value+',';
	}
}

function updates()
{
	var objFrm = document.frmList;
	objFrm.action = '<?=$url?>&action=updates';
	objFrm.submit();
}

var countClick = 0;

function activForm(pur)
{
	objFrm = document.frmEdit;
	if(countClick==0)
	{
		curName = objFrm.nname.value;
		curDir = objFrm.dir.value;
		curID = objFrm.CURID.value;
		curOrder = objFrm.order.value;
		curView = objFrm.view.checked;
	}
	objFrm.nname.readOnly = 0;
	objFrm.dir.readOnly = 0;
	objFrm.order.readOnly = 0;
	objFrm.view.disabled = false;
	objFrm.image.style.display = "";
	document.all["btnUpdate"].style.display = "";
	document.all["btnCancel"].style.display = "";
	if(document.all["btnEdit"]) document.all["btnEdit"].style.display = "none";
			
	if(pur=='insert')
	{			
		objFrm.nname.value = '';
		objFrm.dir.value = '';
		objFrm.order.value = '20';
		objFrm.view.checked = true;
		objFrm.CURID.value = '';
		document.all["FLAG"].style.display = "none";
		if(document.all["btnDelete"]) document.all["btnDelete"].style.display = "none";
	}
	if(pur=='edit' && countClick>0)
	{
		objFrm.nname.value = curName;
		objFrm.dir.value = curDir;
		objFrm.order.value = curOrder;
		objFrm.view.checked = curView;
		objFrm.CURID.value = curID;
	}
	countClick++;
}

function notExe()
{
	document.all["btnUpdate"].style.display = "none";
	document.all["btnCancel"].style.display = "none";
	document.all["btnEdit"].style.display = "";
	document.all["btnDelete"].style.display = "";
	
	document.all["FLAG"].style.display = "";	
	objFrm.image.style.display = "none";
	objFrm.nname.readOnly = 1;
	objFrm.dir.readOnly = 1;
	objFrm.order.readOnly = 1;
	objFrm.view.disabled = true;

	objFrm.nname.value = curName;
	objFrm.dir.value = curDir;
	objFrm.order.value = curOrder;
	objFrm.CURID.value = curID;
}

function checkSubmit()
{
	if(objFrm.nname.value=="")
	{
		alert("Ban vui long nhap tieu de cho danh muc!");
		objFrm.nname.focus();
		return false;
	}		
	return true;
}

function doSubmit()
{
	objFrm = document.frmEdit;
	if(checkSubmit()) objFrm.submit();
}

function update()
{
	var myform = document.frmDefine;
	var numElem = myform.length;
	for(i=0;i<numElem;i++)
	{
		if(myform.elements[i].type!='hidden')
		{
			myform.config_name.value += myform.elements[i].name+"~";
			myform.config_value.value += myform.elements[i].value+"~";
		}
	}
	myform.submit();
}

function newObj()
{
	var fname = "<?=$module?>/add_define.php?CURID=<?=$CURID?>";
	openBox(fname,400,300,'no');
}
</script>
